package com.sportschain.app.homepage.activity;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Switch;

import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.chart.common.dataentry.DataEntry;
import com.anychart.chart.common.dataentry.ValueDataEntry;
import com.anychart.charts.Cartesian;
import com.anychart.core.cartesian.series.Area;
import com.anychart.core.ui.Crosshair;
import com.anychart.data.Mapping;
import com.anychart.data.Set;
import com.anychart.enums.HoverMode;
import com.anychart.enums.ScaleStackMode;
import com.anychart.enums.TooltipDisplayMode;
import com.anychart.graphics.vector.Stroke;
import com.sportschain.app.R;
import com.sportschain.app.core.base.BaseActivity;
import com.sportschain.app.homepage.adatper.StepHistoryAdapter;
import com.sportschain.app.homepage.bean.StepHistoryBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class StepCountActivity extends BaseActivity {


    @BindView(R.id.week_switch)
    Switch mWeekSwitch;
    @BindView(R.id.step_history_rv)
    RecyclerView mStepHistoryRv;
    @BindView(R.id.step_chart_view)
    AnyChartView mStepChartView;

    private StepHistoryAdapter mAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_step_count;
    }

    @Override
    public void initView() {
        mAdapter = new StepHistoryAdapter();
        mAdapter.bindToRecyclerView(mStepHistoryRv);

        initChartView();
    }

    @Override
    public void initData() {
        List<StepHistoryBean> data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            data.add(new StepHistoryBean());
        }
        mAdapter.setNewData(data);
    }

    @Override
    public void initListener() {

    }

    @OnClick({R.id.week_switch, R.id.step_history_rv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.week_switch:
                break;
            case R.id.step_history_rv:
                break;
            default:
                break;
        }
    }

    private void initChartView() {


        Cartesian areaChart = AnyChart.area();

        areaChart.animation(true);

        Crosshair crosshair = areaChart.crosshair();
        crosshair.enabled(true);
        // TODO yStroke xStroke in crosshair
        crosshair.yStroke((Stroke) null, null, null, (String) null, (String) null)
                .xStroke("#fff", 1d, null, (String) null, (String) null)
                .zIndex(39d);
        crosshair.yLabel(0).enabled(true);

        areaChart.yScale().stackMode(ScaleStackMode.VALUE);

        areaChart.title(false);

        List<DataEntry> seriesData = new ArrayList<>();
        seriesData.add(new ValueDataEntry("一", 2200));
        seriesData.add(new ValueDataEntry("二", 2800));
        seriesData.add(new ValueDataEntry("三", 2400));
        seriesData.add(new ValueDataEntry("四", 3200));
        seriesData.add(new ValueDataEntry("五", 3400));
        seriesData.add(new ValueDataEntry("六", 3000));
        seriesData.add(new ValueDataEntry("日", 2600));

        Set set = Set.instantiate();
        set.data(seriesData);
        Mapping series1Data = set.mapAs("{ x: 'x', value: 'value' }");

        Area series1 = areaChart.area(series1Data);
        series1.stroke("3 #fff");


        areaChart.legend().enabled(false);
        areaChart.legend().fontSize(13d);
        areaChart.legend().padding(0d, 0d, 20d, 0d);

        areaChart.xAxis(0).title(false);
        areaChart.yAxis(false).title(false);

        areaChart.interactivity().hoverMode(HoverMode.BY_X);
        areaChart.tooltip()
                .displayMode(TooltipDisplayMode.UNION);

        mStepChartView.setChart(areaChart);
    }


}
